

import logging

from api.monitor.monitor_api import MonitorAPI
from api.parameter.parameter_api import ParameterAPI
from api.zhansuo.zhansuo_api import ZhanSuoAPI
from business_data import yewu_config
from business_data.yewu_config import device_dict


# from conftest.conftest import start_login
class YeWuUtil:

    # 获取站所id
    # 根据站点名字查看站所
    @classmethod
    def get_zhansuo_id(cls, start_login, deviceName):
        resp = ZhanSuoAPI.query_deptCodeList(start_login)
        data = resp.json().get("data")
        if len(data) == 0:
            logging.info("没有找到站所")
            return 0
        else:
            for row in data:
                if row.get("deptName") == deviceName:
                    # logging.info(f"找到了站所：{deviceName}")
                    stationId = row.get("stationId")
                    return stationId

        pass

    # 根据字典标签，查找字典值 deviceBigType dictLabel":"安全防范","dictValue":"3000"   device_large_type
    @classmethod
    def get_dict_value(cls, start_login, dictLabel, param_manage):
        resp = ParameterAPI.query_paramDict_list(start_login, dictLabel=dictLabel, param_manage=param_manage)
        deviceBigType = resp.json().get("rows")[0].get("dictValue")
        return deviceBigType

    # 获取#设备参数字典 tag_value
    @classmethod
    def get_deviceValue(cls):
        list_device = []
        for device in device_dict:
            list_device.append(device.get("tag_value"))

        return list_device

    #根据设备名称查询设备id
    @classmethod
    def query_deviceIDByName(cls,token,equName):
        resp =MonitorAPI.query_cmDevice(token,equName)
        if resp.json().get("total")!=0:
            deviceId = resp.json().get("rows")[0].get("id")
            return deviceId
        else:
            logging.error(f"在监测设备里面没有搜到：{equName}")
            return ''

if __name__ == '__main__':
    YeWuUtil.get_dict_value(yewu_config.monitor_system, "device_large_type")
